package com.codecash.mapper;

import com.codecash.entity.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskMapper {
    //发布任务
    @Insert("INSERT INTO tasks (task_type, title, content, budget, author_id, contact_person, contact_info, create_time, update_time, status) " +
            "VALUES (#{taskType}, #{title}, #{content}, #{budget}, #{authorId}, #{contactPerson}, #{contactInfo}, #{createTime}, #{updateTime}, #{status})")
    void create(Task task);

    //查询

    @Select("select * from tasks where id =#{id}")
    Task getTaskById(Long id);

    //修改
    @Update("UPDATE tasks SET task_type=#{taskType}, title=#{title}, content=#{content}, budget=#{budget}, " +
            "contact_person=#{contactPerson}, contact_info=#{contactInfo}, update_time=#{updateTime}, status=#{status} WHERE id = #{id}")
    void update(Task task);

    //删除
    @Delete("DELETE FROM tasks WHERE id = #{id}")
    void delete(Long task);

    //分页查询
    List<Task> list(Integer taskId);
    //查询用户的任务
    @Select("SELECT id,task_type, title, content, budget, author_id, contact_person, contact_info, create_time, update_time " +
            "FROM tasks WHERE author_id = #{currentUserId} ")
    List<Task> findAllmyTasks(Long currentUserId);

    @Update("UPDATE tasks SET status = #{status} WHERE id = #{taskId}")
    void updateStatus(@Param("taskId") Long taskId, @Param("status") String status);
}
